package com.wonders.hisdoctor.station.project.vaccine.controller;

import com.wonders.his.common.utils.PageUtil;
import com.wonders.his.common.utils.validator.group.InsertGroup;
import com.wonders.hisdoctor.station.constant.Constants;
import com.wonders.hisdoctor.station.project.vaccine.service.IVaccineStockService;
import com.wonders.hisdoctor.station.project.vaccine.domain.VaccineStock;
import com.wonders.his.common.bean.BaseResult;
import com.wonders.his.common.utils.validator.ValidateUtils;
import com.wonders.his.common.utils.validator.group.PrimaryGroup;
import com.wonders.hisdoctor.station.project.vaccine.vo.SetStatusVo;
import com.wonders.hisdoctor.station.project.vaccine.vo.VaccineStockRequestVo;
import com.wonders.hisdoctor.station.project.vaccine.vo.VaccineStockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhanghaonan
 * @date 2021/06/25
 */
@Api(tags = "疫苗库存信息")
@RestController
@RequestMapping("/vaccine/vaccinestock")
public class VaccineStockController {

    @Autowired
    private IVaccineStockService vaccineStockService;

    /**
     * 新增
     *
     * @param vaccineStock
     * @return
     */
    @ApiOperation("新增")
    @PostMapping("add")
    public BaseResult<Integer> add(@RequestBody VaccineStock vaccineStock, HttpServletRequest request) {
        ValidateUtils.validateEntity(vaccineStock, new Class[]{InsertGroup.class});
        return BaseResult.success(vaccineStockService.save(vaccineStock, request));
    }

    /**
     * 修改
     *
     * @param vaccineStock
     * @return
     */
    @ApiOperation("修改")
    @PostMapping("update")
    public BaseResult<Integer> update(@RequestBody VaccineStock vaccineStock, HttpServletRequest request) {
        ValidateUtils.validateEntity(vaccineStock, new Class[]{PrimaryGroup.class, InsertGroup.class});
        return BaseResult.success(vaccineStockService.update(vaccineStock, request));
    }

    /**
     * 主键查询
     *
     * @param vaccineStock
     * @return
     */
    @ApiOperation("主键查询")
    @PostMapping("queryByKey")
    public BaseResult<VaccineStock> queryByPrimaryKey(@RequestBody VaccineStock vaccineStock) {
        ValidateUtils.validateEntity(vaccineStock, PrimaryGroup.class);
        return BaseResult.success(vaccineStockService.getById(vaccineStock));
    }

    /**
     * 主键删除
     *
     * @param vaccineStock
     * @return
     */
    @ApiOperation("主键删除")
    @PostMapping("removeByKey")
    public BaseResult<Integer> delete(@RequestBody VaccineStock vaccineStock, HttpServletRequest request) {
        ValidateUtils.validateEntity(vaccineStock, PrimaryGroup.class);
        return BaseResult.success(vaccineStockService.removeById(vaccineStock, request));
    }

    /**
     * 模糊查询
     *
     * @param vo
     * @return
     */
    @ApiOperation("模糊查询")
    @PostMapping("search")
    public BaseResult<List<VaccineStockVo>> search(@RequestBody VaccineStockRequestVo vo) {
        PageUtil.startPage();
        return BaseResult.success(PageUtil.getDataTable(vaccineStockService.search(vo)));
    }

    /**
     * 设置疫苗状态
     *
     * @param vo
     * @return
     */
    @ApiOperation("设置疫苗状态")
    @PostMapping("setStatus")
    public BaseResult<Integer> setStatus(@RequestBody SetStatusVo vo, HttpServletRequest request) {
        return BaseResult.success(vaccineStockService.setStatus(vo, request));
    }

    /**
     * 疫苗下拉框
     *
     * @param vo
     * @return
     */
    @ApiOperation("疫苗下拉框")
    @PostMapping("vaccineSelect")
    public BaseResult<List<VaccineStockVo>> vaccineSelect(@RequestBody VaccineStockRequestVo vo) {
        PageUtil.startPage();
        vo.setSupplyIndicator(Constants.AVAILABLE);
        return BaseResult.success(PageUtil.getDataTable(vaccineStockService.search(vo)));
    }
}